import {legacy_createStore,applyMiddleware} from "redux"
import logger from "redux-logger"
import thunk from "redux-thunk";
import {ALLSTATION,ALLSTATE,GETCLASSIFY,GETSORT,ADDDETAIL,GETLIST} from "../types/store.d"
const initialState = {
    classifyArr:[],
    listArr:[],
    sortArr:[],
    bookArr:[],
}

const reducer=(state:ALLSTATE = initialState, { type, payload }:ALLSTATION) => {
  switch (type) {

  case GETCLASSIFY:
      let arr=[...state.classifyArr];
      arr=payload;
      state.classifyArr=arr
    return { ...state }
    case GETLIST:
      let arr1=[...state.listArr];
      arr1=payload;
      state.listArr=arr1
      return { ...state }
      case GETSORT:
        let arr2=[...state.sortArr];
        arr2=payload;
        state.sortArr=arr2
      return { ...state }
      case ADDDETAIL:
        let arr3=[...state.bookArr];
        arr3.push(payload);
        state.bookArr=arr3
        return { ...state }
  default:
    return state
  }
}
const store =legacy_createStore(reducer,applyMiddleware(logger,thunk))
export default store;